<?php
	/**
	 * 获取签到奖品列表
	 */
    class SignInPriceList extends APIBase {
		
		public $tag = "SignInPriceList";
    	public $isLogin = true;
		
		public function before() {
			$this->initCacheRedis();
			$this->initMysql();
			return true;
		}
		public function logic(){
			$playerID = $this->uid;
			$signreward = $this->cache_redis->keys("hsignreward:*");
			$result = array();
			$count = count($signreward);
			for($i=1;$i<=$count;$i++){
				$list = $this->cache_redis->hGetAll("hsignreward:".$i);
				$msglist = $this->cache_redis->hGetAll("hmg:".$list['mid']);
				$rewardlist = json_decode($list['reward'],true);
				$rewardrow = array();
				foreach($rewardlist as $key=>$val){
					$proplist = $this->cache_redis->hGetAll("prop:".$key);
					$rewardrow[] = array("name"=>$proplist['name'],"count"=>$val);
				}
				$result['signlist'][] = array("id"=>$list['id'],"title"=>$msglist['title'],'reward'=>$rewardrow);
			}
			
					
			//获取签到列表
			$signlist = $this->cache_redis->hMGet("hSign:{$playerID}", array('uid','is_sign','signcount','signdate'));	

			$ts = time();
			//判断是否签到过,并返回签到的天数
			if(!$signlist['uid']){
				$signcount = 0;
				$result['signcount'] = (int)$signcount;
				$this->returnData($result);
			}else{
				if($signlist['is_sign']==0 && (strtotime(date("Y-m-d",$ts))-strtotime(date("Y-m-d",$signlist['signdate'])))/24/3600<=1){//判断是否连天签到
					$signcount = (int)$signlist['signcount'];
					if($signcount>=7){
						$result['signcount'] = 6;
						$this->cache_redis->hMset("hSign:{$playerID}", array('signcount'=>6));
					}else{
						$result['signcount'] = $signcount;
						$this->cache_redis->hMset("hSign:{$playerID}", array('signcount'=>$signcount));
					}
					$this->returnData($result);
				}elseif($signlist['is_sign']==0 && (strtotime(date("Y-m-d",$ts))-strtotime(date("Y-m-d",$signlist['signdate'])))/24/3600 >1){//不是连天签到
				    $signcount = 0;
					$result['signcount'] = (int)$signcount;
                    $this->cache_redis->hMset("hSign:{$playerID}", array('signcount'=>0));
					//echo "<pre>";
					//var_dump($result);
					$this->returnData($result);
				}
			}
		}
        public function after() {
			$this->deinitCacheRedis();
		}
    }
?>
